// app.js
App({
  onLaunch(){
    //云开发初始化环境 
    wx.cloud.init({
      env:'xixhaha-7gm9iqp52829762b'
      
    })
    //调用用函数获取用户oppenid
  
    var that = this;
    wx.cloud.callFunction({
      name:'shop_get_openid',
      success(res){
        console.log(res.result.opeind)
        that.globalData.openid = res.result.opeind
      }
    })
    if(wx.getStorageSync('cartList')){
      this.globalData.cartList =wx.getStorageSync('cartList')
    }
    if(wx.getStorageSync('userInfo')){
      this.globalData.userInfo =wx.getStorageSync('userInfo')
    }
    wx.cloud.callFunction({
      name:'shop_get_opeid'
    }).then(res=>{
      console.log(res.result.openid)
      that.globalData.openid = res.result.openid
      //查找数据库用户表里面是否有这个用户记录 
      wx.cloud.database().collection('login_users')
      .where({
        _openid:res.result.opeind
      }).get({
        success(result){
          console.log(result)
          that.globalData.userProfile = result.data[0]
        }
      })

    })
  },
 getUserInfo(){
      wx.cloud.database().collection('shop_users')
      .where({
        _openid:this.globalData.opeind
      })
      .get()
      .then(res=>{
        console.log(res)
        this.globalData.userInfo = res.data[0]
        wx.setStorageSync('userInfo', res.data[0])
      })
    },
  globalData:{
    userInfo:null,
    openid:null,
    //购物车列表
    cartList:[],
    //订单列表
    orderList:null
  }
})


